package leetcode.editor.cn.q1_300.q;

/**
 * @author qidi
 * @date 2021-11-03 11:20:56
 */
class Q0028_ImplementStrstr {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int strStr(String haystack, String needle) {
            if (needle.length() == 0) return 0;
            if (needle.length() > haystack.length()) return -1;
            for (int i = 0; i <= haystack.length() - needle.length(); i++) {
                if (haystack.charAt(i) == needle.charAt(0)) {
                    int j = 0;
                    for (; j < needle.length(); j++) {
                        if (haystack.charAt(i + j) != needle.charAt(j)) {
                            break;
                        }
                    }
                    if (j == needle.length()) {
                        return i;
                    }
                }
            }
            return -1;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0028_ImplementStrstr().new Solution();
        System.out.println(solution.strStr("mississippi", "issip"));
        System.out.println(solution.strStr("", ""));
    }
}